<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$errors = array();

if ($route->POST('action') == 'add')
{
	$name = UV::readMQ($route->POST('name'));
	$e_mail = UV::readMQ($route->POST('e_mail'));
	$site_name = UV::readMQ($route->POST('site_name'));
	$url = UV::readMQ($route->POST('url'));
	$city = UV::readInt($route->POST('city'));
	$power = $route->POST('power') ? "1" : "0";
	$show_main = $route->POST('show_main') ? "1" : "0";

	echo $query = "insert into `business_partners` values(NULL,'{$name}','{$e_mail}','{$site_name}','{$url}','{$city}','{$power}','{$show_main}')";
	echo mysql_error();
	if ($db->sendQuery($query))
		goToPage("/admin/partners/edit/".mysql_insert_id());
}

require_once ADMIN.DS."/head.php";
?>

<h1>Добавление сайта</h1><br /><?php
	if (count($errors) > 0)
		echo "<p class='fail'>".implode("<br />",$errors)."<br /><br /></p>";
?>
<form method='POST'>
	<input type='hidden' name='action' value='add' />
	<table cellpadding='3' cellspacing='5'>
		<tr>
			<td width='170px'><label for="name">Имя контакта</label></td>
			<td width='300px'><input type='text' id="name" name='name' value='<?php echo $route->POST("name"); ?>' /></td>
		</tr>
		<tr>
			<td><label for="email">E-mail</label></td>
			<td><input type='text' id="email" name='e_mail' value='<?php echo $route->POST("e_mail"); ?>' /></td>
		</tr>
		<tr>
			<td><label for="site_name">Название</label></td>
			<td><input type='text' id='site_name' name='site_name' value='<?php echo $route->POST("site_name"); ?>' /></td>
		</tr>
		<tr>
			<td><label for="url">URL</label></td>
			<td><input type='text' id="url" name='url' value='<?php echo $route->POST("url") ? $route->POST("url") : "http://"; ?>' /></td>
		</tr>
		<tr>
			<td><label for='city'>Город</label></td>
			<td>
				<select name="city" id="city" class="double_short">
					<option value="0">Вся Россия</option>
					<option disabled="disabled">———————————</option>
					<?php
					$cities_list = $db->getTable("select `city_id`,`name` from `city` order by `name`");
					echo select_create($cities_list,"city_id","name",$route->POST('city'));
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td><label for="power">Включен</label></td>
			<td><input type='checkbox' id="power" name='power' <?php if ($route->POST("power")) echo "checked='checked'"; ?> /></td>
		</tr>
		<tr>
			<td><label for="show_main">На главной</label></td>
			<td><input type='checkbox' id="show_main" name='show_main' <?php if ($route->POST("show_main")) echo "checked='checked'"; ?> /></td>
		</tr>
		<tr>
			<td colspan='2' align='right'><input type='submit' value='Добавить' /></td>
		</tr>
	</table>
</form>

<?php require_once ADMIN.DS."footer.php"; ?>